﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PlugIn
{
    /// <summary>
    /// This factory provides a way for the rest of the KaiTrade system to 
    /// access execution algos written in this plug in. The actual algos should
    /// impliment KaiTrade.Interfaces.ORStrategyAlgorithm
    /// </summary>
    class ORAlgoFactory : KaiTrade.Interfaces.K2InstanceFactory
    {
        /// <summary>
        /// Singleton 
        /// </summary>
        private static volatile ORAlgoFactory s_instance;

        /// <summary>
        /// used to lock the class during instantiation
        /// </summary>
        private static object s_Token = new object();

        private List<string> m_Names;

        /// <summary>
        /// Logger
        /// </summary>
        public log4net.ILog m_Log = log4net.LogManager.GetLogger("Kaitrade");



        public static ORAlgoFactory Instance()
        {
            // Uses "Lazy initialization" and double-checked locking
            if (s_instance == null)
            {
                lock (s_Token)
                {
                    if (s_instance == null)
                    {
                        s_instance = new ORAlgoFactory();
                    }
                }
            }
            return s_instance;
        }

        protected ORAlgoFactory()
        {
            // Add the names of the order routing algos you want to expose to 
            // rest of kaitrade
            m_Names = new List<string>();
            m_Names.Add("XYZOrdAlg");
            m_Names.Add("ABCAlgo");
           
        }


        public object CreateInstance(string name)
        {
            object myObject = null;
            switch (name)
            {
               
                case "XYZOrdAlg":
                    // Create some object of the that impliments KaiTrade.Interfaces.ORStrategyAlgorithm
                    //myObject = new BBCustomAlg1();
                    break;
                case "ABCAlgo":
                    // Create some object of the that impliments KaiTrade.Interfaces.ORStrategyAlgorithm
                    //myObject = new K2BracketA();
                    break;
                
                default:
                    break;
            }
            return myObject;
        }

        public List<string> Names
        {
            get { return m_Names; }
        }
    }
}
